package com.trainfinder.proxy;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class RemoteRunnable extends AbstractRemoteRunnable {

	private ServiceProvider serviceProvider;

	public RemoteRunnable(ServiceProvider serviceProvider, Logger logger,
			int uniqueIndex) {
		super(logger, uniqueIndex);
		this.serviceProvider = serviceProvider;
	}

	@Override
	protected Service getService() {
		return new AbstractService() {

			public InputStream getInputStream() throws ServerCreationException {
				try {
					return serviceProvider.getRemoteService().getInputStream();
				} catch (IOException e) {
					throw new ServerCreationException(e);
				} catch (ServerCreationException e) {
					throw new ServerCreationException(e);
				}
			}

			public OutputStream getOutputStream()
					throws ServerCreationException {
				try {
					return serviceProvider.getLocalService().getOutputStream();
				} catch (IOException e) {
					throw new ServerCreationException(e);
				} catch (ServerCreationException e) {
					throw new ServerCreationException(e);
				}
			}

		

		};

	}
}
